﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Domain.UserManageDomain
{
    public class RoleInfoService:IRoleInfoService
    {
        private IRoleInfoRepository _IRoleInfoRepository;
        private IMapper _Mapper;
        private readonly ISnowflake _snowflake;
        public RoleInfoService(IRoleInfoRepository roleInfoRepository,IMapper mapper, ISnowflake snowflake)
        {
            _Mapper=mapper;
            _snowflake=snowflake;
            _IRoleInfoRepository = roleInfoRepository;
        }

        public async Task<bool> AddRoleInfoAsync(RoleInfoApiDto roleInfoDto)
        {
            RoleInfo roleInfo = new RoleInfo();
            _Mapper.Map(roleInfoDto,roleInfo);
           return await _IRoleInfoRepository.AsSugarClient().Insertable(roleInfo).IgnoreColumns("Name","ParentID").
                ExecuteCommandIdentityIntoEntityAsync();
        }


        public async Task<List<RoleInfoApiDto>> GetRoleInfoAsync()
        {
            List<RoleInfoApiDto> roleInfoDtos = new List<RoleInfoApiDto>();
            var reuslt=await _IRoleInfoRepository.GetListAsync();
            _Mapper.Map(reuslt,roleInfoDtos);
            return roleInfoDtos;
        }

        public async Task<bool> DeleteRoleInfoAsync(long roleID)
        {
            return await _IRoleInfoRepository.Delete(x=>x.ID==roleID).ToAsync();
        }
    }
}
